package com.mjk.rest.system;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mjk.common.rest.BaseController;
import com.mjk.common.vo.TableResponse;
import com.mjk.model.system.Element;
import com.mjk.service.system.ElementService;

import tk.mybatis.mapper.entity.Example;

@RestController
@RequestMapping("api/element")
public class ElementController extends BaseController<ElementService, Element>{

	@RequestMapping(value="list", method = RequestMethod.GET)
	public TableResponse<Element> page(@RequestParam(defaultValue="10")int limit, @RequestParam(defaultValue="1")int offset, 
			String name, @RequestParam(defaultValue="0")int menuId){
		Example example = new Example(Element.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("menuId", menuId);
		if(StringUtils.isNotBlank(name)){
			criteria.andLike("name", "%" + name + "%");
		}
		List<Element> list = baseBiz.selectByExample(example);
		return new TableResponse<Element>(list.size(), list);
	}
}
